<?php

if ($this->isAjax == ""){
    echo '<div id="divSponsor">';
}
?>

    <div class="page-header">
        <h1>
            Jaringan Sponsor
            <small>
                <i class="icon-double-angle-right"></i>
                Jaringan Sponsor / Matahari
            </small>
        </h1>
    </div>

    
    <div class="row">
        <div class="col-xs-11">
            <!-- PAGE CONTENT BEGINS -->
            
            <div class="widget-box transparent" align="center">
                <span class="green middle bolder">&nbsp;
                    <?php
                    if ($this->memberLogin != $this->memberId){
                    ?>
                    <a href='#' data-action="reload" onclick="getUpline(<?php echo $this->upline;?>)">Upline</a>
                    <br>
                <br>
                    <?php } ?>
                </span>
                
        </div>

        <div id="timeline">
                <div class="row">
                        <div class="col-xs-12 col-sm-10 col-sm-offset-1">
                            
                                <?php
                                $datenya = "";
                                $start = 0;
                                $num = 0;
                                while($this->data->next()){
                                    $res = $this->data->current();
                                    $num++;
                                    $divTutup = "";
                                    $divTutup2 = "";
                                    
                                    if ($res['dateline'] != $datenya){
                                        $datenya = $res['dateline'];
                                        
                                        if ($start > 0){
                                            echo "</div>\n";
                                            echo "</div>\n";
                                        }
                                        
                                        $start++;

                                        $label = "label-grey";

                                        if ($res['dateline'] == 'Today')
                                            $label = "label-primary";
                                        else if ($res['dateline'] == 'Yesterday')
                                            $label = "label-success";
                                        

                                ?>
                                <div class="timeline-container">

                                    <div class="timeline-label">
                                            <span class="label <?php echo $label;?> arrowed-in-right label-lg">
                                                    <b><?php echo $res['dateline']; ?></b>
                                            </span>
                                    </div>

                                    <div class="timeline-items">
                                    <?php
                                    }
                                    
                                    $divTutup2 = "</div>";
                                    $userPhoto = ($res["img_profile"] != "") ? "/img/profile/".$res["img_profile"] : "/assets/avatars/avatar4.png";
                                    ?>
                                        <div class="timeline-item clearfix">
                                                <div class="timeline-info">
                                                        <img alt="Susan't Avatar" src="<?php echo $this->basePath().$userPhoto;?>" />
                                                        <span class="label label-info label-sm"><?php echo $res['timeline']; ?></span>
                                                </div>

                                                <div class="widget-box transparent">
                                                        <div class="widget-header widget-header-small">
                                                                <h5 class="smaller">
                                                                    <a data-action="reload" onclick="getChild(<?php echo $res['id']; ?>, <?php echo $this->memberId;?>)" href="sponsor?memberId=<?php echo $res['id']; ?>" class="blue"><?php echo $res['member_code']; ?></a>
                                                                        <span class="grey"><?php echo $res['member_name']; ?></span>
                                                                </h5>

                                                                <span class="widget-toolbar no-border">
                                                                        <i class="icon-time bigger-110"></i>
                                                                        <?php echo $res['timeline']; ?>
                                                                </span>

                                                                <span class="widget-toolbar">
                                                                        <!--a href="#" data-action="reload">
                                                                                <i class="icon-refresh"></i>
                                                                        </a-->

                                                                        <a href="#" data-action="collapse">
                                                                                <i class="icon-chevron-up"></i>
                                                                        </a>
                                                                </span>
                                                        </div>

                                                        <div class="widget-body">
                                                                <div class="widget-main">
                                                                    <?php 
                                                                     echo $res['address']."<br><br>";
                                                                     echo "Tlp: ".$res['contact_phone']."<br>";
                                                                     echo "HP: ".$res['contact_mobile']."<br>";
                                                                     echo "Email: ".$res['contact_email'];
                                                                     ?>
                                                                    
                                                                </div>
                                                        </div>
                                                </div>
                                        </div>                                        

                                <?php
                                   
                                }

                                

                                if ($num == 0){
                                    echo "Tidak memiliki jaringan.";
                                }else{
                                     echo "</div>\n";
                                     echo "</div>\n";
                                }
                                ?>     
                                       
                                        <!-- /.timeline-items -->
                                        <!-- /.timeline-container -->
                        </div>
                </div>
        </div>

        

            <!-- PAGE CONTENT ENDS -->
        </div>
    </div>

<?php
if ($this->isAjax == ""){
    echo "</div>";

?>
<script>




function getChild(memberId, upline) {

        
        $.ajax({
            url: 'sponsor',
            type: "get",
            data: {memberId : memberId, upline: upline, isAjax: 1},
            success: function(response, opts){
                var cekmember = response.search('Tidak memiliki jaringan');

                if (cekmember < 0){
                        $("#divSponsor").html(response);                    
                }else alert("Tidak memiliki jaringan");

            },
            error:function(response, opts){
                $("#divSponsor").html(response);

            }
        });
};

function getUpline(memberId) {

        
        $.ajax({
            url: 'sponsor',
            type: "get",
            data: {memberId : memberId, isAjax: 1},
            success: function(response, opts){
                var cekmember = response.search('Tidak memiliki jaringan');

                if (cekmember < 0){
                        $("#divSponsor").html(response);
                }else alert("Tidak memiliki jaringan");

            },
            error:function(response, opts){
                $("#divSponsor").html(response);

            }
        });
};


</script>

<?php }
?>